<template>
  <div class="main" v-loading="loading">
    <el-row class="action">
      <el-col :span="24">
        <el-button-group>
          <el-button @click="funStartOperation" v-if="
              OperatePermission.Start !== undefined &&
                OperatePermission.Start.IsVisible
            "><i class="el-icon-document-checked" />提交</el-button>
          <el-button @click="funSaveInfo" v-if="
              OperatePermission.Save !== undefined &&
                OperatePermission.Save.IsVisible
            "><i class="fa fa-save" />暂存</el-button>
          <el-button @click="$refs.CCOperationDialog.visible = true" v-if="
              OperatePermission.CopySend !== undefined &&
                OperatePermission.CopySend.IsVisible
            ">
            <nx-svg-icon class-name="cc-icon" icon-class="cc" />抄送
          </el-button>
          <el-button @click="processApproval()" v-if="
              OperatePermission.Approval !== undefined &&
                OperatePermission.Approval.IsVisible
            "><i class="el-icon-circle-check" />同意</el-button>
          <el-button @click="processReject()" v-if="
              OperatePermission.Sendback !== undefined &&
                OperatePermission.Sendback.IsVisible
            ">
            <nx-svg-icon class-name="return-icon" icon-class="return" />
            驳回
          </el-button>
          <el-button @click="$refs.TurnOperationDialog.visible = true" v-if="
              OperatePermission.Tranfer !== undefined &&
                OperatePermission.Tranfer.IsVisible
            ">
            <nx-svg-icon class-name="tranfer-icon" icon-class="tranfer" />
            转办
          </el-button>
          <el-button @click="$refs.CommunicationDialog.visible = true" v-if="
              OperatePermission.StartQuery !== undefined &&
                OperatePermission.StartQuery.IsVisible
            "><i class="el-icon-position" /> 发起沟通</el-button>
          <el-button @click="$refs.AnswerCommunicationDialog.visible = true" v-if="
              OperatePermission.AnswerQuery !== undefined &&
                OperatePermission.AnswerQuery.IsVisible
            "><i class="fa fa-comments" />回复沟通</el-button>
          <el-button @click="funCancerCommunication()" v-if="
              OperatePermission.CancelQuery !== undefined &&
                OperatePermission.CancelQuery.IsVisible
            "><i class="fa fa-remove" /> 取消沟通</el-button>
          <el-button @click="$refs.FlowSkipDialog.visible = true" v-if="
              OperatePermission.FlowSkip !== undefined &&
                OperatePermission.FlowSkip.IsVisible
            "><i class="fa fa-forward" />跳转</el-button>
          <el-button @click="funTurnOperation()" v-if="
              OperatePermission.HastenWork !== undefined &&
                OperatePermission.HastenWork.IsVisible
            "><i class="el-icon-message-solid" />催办</el-button>
          <el-button @click="funCopyStart()" v-if="
              OperatePermission.CopyBut !== undefined &&
                OperatePermission.CopyBut.IsVisible
            "><i class="el-icon-copy-document" />复制草稿</el-button>
          <el-button v-if="
              OperatePermission.Repeal !== undefined &&
                OperatePermission.Repeal.IsVisible
            "><i class="fa fa-reply"></i> 撤销</el-button>
          <el-button @click="$refs.AbandonOperationDialog.visible = true" v-if="
              OperatePermission.Abandon !== undefined &&
                OperatePermission.Abandon.IsVisible
            "><i class="el-icon-delete-solid" />废弃</el-button>
          <el-button v-if="
              OperatePermission.Repeal_App !== undefined &&
                OperatePermission.Repeal_App.IsVisible
            "><i class="fa fa-reply"></i> 撤销</el-button>
          <el-button @click="$refs.AbandonOperationDialog.visible = true" v-if="
              OperatePermission.Abandon_App !== undefined &&
                OperatePermission.Abandon_App.IsVisible
            "><i class="el-icon-delete-solid" />废弃</el-button>
          <el-button @click="funOpenPrint()" v-if="
              OperatePermission.Print !== undefined &&
                OperatePermission.Print.IsVisible
            "><i class="fa fa-print" />打印</el-button>
        </el-button-group>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <a-tabs default-active-key="1">
          <a-tab-pane key="1">
            <span slot="tab">
              <i class="el-icon-document" />
              表单信息
            </span>
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <i class="el-icon-s-grid"></i> <span>基本信息</span>
              </div>
              <el-form ref="elForm" :model="flowFromData" size="medium" :rules="rules" label-width="100px">
                <el-col :span="24">
                  <el-col :span="24">
                    <el-col :xs="24" :md="12" :lg="16" style="padding:0px">
                      <el-col :span="24" style="height:">
                        <el-form-item label="主题" prop="Header_formSubTitle" label-width="100px">
                          <el-input placeholder="请输入主题" v-model="flowFromData.Header_formSubTitle" maxlength="50"></el-input>
                        </el-form-item>
                      </el-col>
                    </el-col>
                    <el-col :xs="24" :md="12" :lg="8" style="padding:0px">
                      <el-col :span="24" style="height:">
                        <el-form-item label="编号" label-width="100px">
                          <el-input placeholder="请输入单行文本内容" v-model="flowFromData.Header_formNumber" maxlength="50" disabled></el-input>
                        </el-form-item>
                      </el-col>
                    </el-col>
                    <el-col :xs="24" :md="12" :lg="8" style="padding:0px">
                      <el-col :span="24" style="height:">
                        <el-form-item label="创建人" label-width="100px">
                          <el-input placeholder="创建人" v-model="flowFromData.Header_CreateUserName" maxlength="50" disabled></el-input>
                        </el-form-item>
                      </el-col>
                    </el-col>
                    <el-col :xs="24" :md="12" :lg="8" style="padding:0px">
                      <el-col :span="24" style="height:">
                        <el-form-item label="创建人部门" label-width="100px">
                          <el-input placeholder="请输入创建人部门" v-model="flowFromData.Header_CreateDepName" maxlength="50" disabled></el-input>
                        </el-form-item>
                      </el-col>
                    </el-col>
                    <el-col :xs="24" :md="12" :lg="8" style="padding:0px">
                      <el-col :span="24" style="height:">
                        <el-form-item label="单据状态" label-width="100px">
                          <el-input placeholder="请输入单据状态" v-model="flowFromData.Header_Document_Status

                            " maxlength="50" disabled></el-input>
                        </el-form-item>
                      </el-col>
                    </el-col>
                    <el-col :xs="24" :md="12" :lg="8" style="padding:0px">
                      <el-col :span="24" style="height:">
                        <el-form-item label="申请人" prop="Header_applicantUserName" label-width="100px">
                          <selector :typemode="1" :ismulti="false" :checklisted="checklisted" @confirm="applicantUserConfirm"></selector>
                        </el-form-item>
                      </el-col>
                    </el-col>
                    <el-col :xs="24" :md="12" :lg="8" style="padding:0px">
                      <el-col :span="24" style="height:">
                        <el-form-item label="申请人部门" label-width="100px">
                          <el-input placeholder="请输入申请人部门" v-model="flowFromData.Header_applicantUser_DepName" maxlength="50" disabled></el-input>
                        </el-form-item>
                      </el-col>
                    </el-col>
                    <el-col :xs="24" :md="12" :lg="8" style="padding:0px">
                      <el-col :span="24" style="height:">
                        <el-form-item label="提交日期" label-width="100px">
                          <el-input placeholder="提交日期" v-model="flowFromData.Header_CreateDate" maxlength="50" disabled></el-input>
                        </el-form-item>
                      </el-col>
                    </el-col>
                  </el-col>
                </el-col>
              </el-form>
            </el-card>
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <i class="el-icon-edit"></i> <span>详细信息</span>
              </div>
              <previewpage ref="previewPagemain" :postData="postData" :propsData="propsData" @loadcomplete="loadfromcomplete" @initFrom="initFrom"></previewpage>
            </el-card>
          </a-tab-pane>
          <a-tab-pane key="2">
            <span slot="tab">
              <i class="el-icon-time" />
              审批记录
            </span>
            <el-table :data="currentapprovallist" style="width: 100%" v-if="currentapprovallist.length>0">
              <el-table-column prop="factname" label="当前处理节点" width="180">
              </el-table-column>
              <el-table-column prop="fapproversname" label="当前处理人" width="180">
              </el-table-column>
              <el-table-column prop="farrivaldate" label="到达时间">
              </el-table-column>
            </el-table>
            <el-table :data="historyapprovallist" style="width: 100%" v-if="historyapprovallist.length > 0">
              <el-table-column prop="factname" label="处理步骤" width="180">
              </el-table-column>
              <el-table-column prop="name" label="处理人" width="180">
                <template slot-scope="scope">
                  <span v-if="
                      scope.row.fapprovelaction == 'System CC' ||
                        scope.row.fapprovelaction == '系统抄送' ||
                        scope.row.fapprovelaction == 'System Cc'
                    ">
                    系统处理
                  </span>
                  <span v-else>
                    {{ scope.row.fapprovelaction }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column prop="fapprovelaction" label="处理动作" width="100">
              </el-table-column>
              <el-table-column prop="factopendate" label="到达时间" width="150">
              </el-table-column>
              <el-table-column prop="factfishdate" label="处理时间" width="150">
              </el-table-column>
              <el-table-column prop="fapproveldescr" label="处理意见">
              </el-table-column>
            </el-table>
          </a-tab-pane>
          <a-tab-pane key="3">
            <span slot="tab">
              <i class="fa fa-usb" />
              流程走向
            </span>
            <iframe ref="PcSurvey" name="PcSurvey" frameborder="0" scrolling="no" :src="'/flow/Flowdesign.html'" class="uploadfile" id="pc_survey" style="height:calc(100vh - 120px);width: 100%;"></iframe>
          </a-tab-pane>
        </a-tabs>
      </el-col>
    </el-row>
    <zhlDialog title="审批" ref="ApprovalOperationDialog" width="800px" class="my-dialog">
      <ApprovalOperation @cancel="$refs.ApprovalOperationDialog.visible = false" @confirm="funApprovalOperation"></ApprovalOperation>
    </zhlDialog>
    <zhlDialog title="抄送" ref="CCOperationDialog" width="800px" class="my-dialog">
      <CCOperation @cancel="$refs.CCOperationDialog.visible = false" @confirm="funCCOperation"></CCOperation>
    </zhlDialog>
    <zhlDialog title="沟通" ref="CommunicationDialog" width="800px" class="my-dialog">
      <Communication @cancel="$refs.CommunicationDialog.visible = false" @confirm="funStartCommunication"></Communication>
    </zhlDialog>
    <zhlDialog title="跳转" ref="FlowSkipDialog" width="800px" class="my-dialog">
      <FlowSkip @cancel="$refs.FlowSkipDialog.visible = false" @confirm="funFlowSkip"></FlowSkip>
    </zhlDialog>
    <zhlDialog title="驳回" ref="RejectOperationDialog" width="800px" class="my-dialog">
      <RejectOperation @cancel="$refs.RejectOperationDialog.visible = false" @confirm="funRejectOperation"></RejectOperation>
    </zhlDialog>
    <zhlDialog title="转办" ref="TurnOperationDialog" width="800px" class="my-dialog">
      <turnoperationcontrol @cancel="$refs.TurnOperationDialog.visible = false" @confirm="funTurnOperation"></turnoperationcontrol>
    </zhlDialog>
    <zhlDialog title="回复沟通" ref="AnswerCommunicationDialog" width="800px" class="my-dialog">
      <AnswerCommunication @cancel="$refs.AnswerCommunicationDialog.visible = false" @confirm="funAnswerCommunication"></AnswerCommunication>
    </zhlDialog>
    <zhlDialog title="废弃" ref="AbandonOperationDialog" width="800px" class="my-dialog">
      <AbandonOperation @cancel="$refs.AbandonOperationDialog.visible = false" @confirm="funAbandonOperation"></AbandonOperation>
    </zhlDialog>
  </div>
</template>
<script>
import previewpage from '@/views/index.vue'
import { ApiGetProcAudit } from '@/api/tappProcaudit'
import { ApiLoadProcessFromInfo } from '@/api/tappProcess'
import { ApiGetProcinstNumber, HandleProcess } from '@/api/tappPorcessins'
import ApprovalOperation from '@/views/Flow/operation/ApprovalOperation.vue'
import CCOperation from '@/views/Flow/operation/CCOperation.vue'
import Communication from '@/views/Flow/operation/Communication.vue'
import FlowSkip from '@/views/Flow/operation/FlowSkip.vue'
import RejectOperation from '@/views/Flow/operation/RejectOperation.vue'
import turnoperationcontrol from '@/views/Flow/operation/turnoperationcontrol.vue'
import AnswerCommunication from '@/views/Flow/operation/AnswerCommunication.vue'
import AbandonOperation from '@/views/Flow/operation/AbandonOperation.vue'
export default {
  data () {
    return {
      historyapprovallist: [],
      currentapprovallist: [],
      postData: {},
      propsData: {},
      flowFromData: {
        Header_formSubTitle: '',
        Header_formNumber: '',
        Header_CreateUserName: '',
        Header_CreateUserID: '',
        Header_CreateDepName: '',
        Header_CreateDepID: '',
        Header_Document_Status: '发起',
        Header_applicantUserID: '',
        Header_applicantUserName: '',
        Header_applicantUser_DepName: '',
        Header_applicantUser_DepID: '',
        Header_CreateDate: ''
      },
      ProcID: '',
      ProcInsID: '',
      ActInsID: '',
      userInfo: {
        Organid: '',
        Organname: '',
        Organcode: '',
        Deptcode: '',
        userName: '',
        userNo: '',
        deptName: '',
        deptID: '',
        DateTime: '',
        DeviceType: '',
        EncryptString: ''
      },
      rules: {
        Header_formSubTitle: [
          {
            required: true,
            message: '流程主题必填',
            trigger: 'blur'
          }
        ],
        Header_applicantUserName: [
          {
            required: true,
            message: '申请人必填',
            trigger: 'blur'
          }
        ]
      },
      flowhead: {},
      DataPermission: {},
      flowChart: {},
      OperatePermission: {},
      AttachmentPermission: {},
      IsRead: false,
      actid: '',
      processName: '',
      BusinessModuleID: '',
      BusinessMoudle: '',
      checklisted: [],
      Mobile: '',
      operateType: '',
      flowstatusName: '',
      flowstatus: '',
      loading: false,
      procinsstate: [
        '发起',
        '草稿',
        '处理中',
        '',
        '已完成',
        '已废弃',
        '已撤销',
        '待系统处理',
        '审批失败',
        '审批异常',
        '流程异常'
      ],
      viewmodel: '', /// todo 从待办进入 read 只读 start 我的发起 draft 我的草稿
      fromcotrol: null
    }
  },
  components: {
    previewpage,
    ApprovalOperation,
    CCOperation,
    Communication,
    FlowSkip,
    RejectOperation,
    turnoperationcontrol,
    AnswerCommunication,
    AbandonOperation
  },
  created () {
    this.ProcID = this.$query('processid')
    this.ProcInsID = this.$query('processinsid')
    this.ActInsID = this.$query('actinsid')
    this.viewmodel = this.$query('viewmodel')
    this.GetProcAudit()
    this.LoadProcessFromInfo()
  },
  methods: {
    /// 加载审批记录
    GetProcAudit () {
      if (
        this.ProcInsID !== '' &&
        this.ProcInsID !== undefined &&
        this.ProcInsID !== null
      ) {
        this.historyapprovallist = []
        this.currentapprovallist = []
        ApiGetProcAudit({ procinstanceid: this.ProcInsID }).then(res => {
          if (res.code === 0) {
            res.data.forEach(item => {
              if (item.iscurrent) {
                this.currentapprovallist.push(item)
              } else {
                this.historyapprovallist.push(item)
              }
            })
          } else {
            this.$message.error('获取审批记录报错！')
          }
        })
      }
    },
    /// 加载流程信息
    LoadProcessFromInfo () {
      if (
        this.ProcID !== '' &&
        this.ProcID !== undefined &&
        this.ProcID !== null
      ) {
        this.loading = true
        ApiLoadProcessFromInfo({
          processid: this.ProcID,
          processinsid: this.ProcInsID,
          actinsid: this.ActInsID,
          viewmodel: this.viewmodel
        }).then(res => {
          this.loading = false
          if (res.code === 0) {
            this.userInfo = res.data.currentUserInfo
            this.flowFromData.Header_formSubTitle = ''
            this.flowFromData.Header_formNumber = ''
            this.flowFromData.Header_CreateUserName = this.userInfo.username
            this.flowFromData.Header_CreateUserID = this.userInfo.userno
            this.flowFromData.Header_CreateDepName = this.userInfo.deptname
            this.flowFromData.Header_CreateDepID = this.userInfo.deptid

            this.flowFromData.Header_applicantUserID = this.userInfo.userno
            this.flowFromData.Header_applicantUserName = this.userInfo.username
            this.flowFromData.Header_applicantUser_DepName = this.userInfo.deptname
            this.flowFromData.Header_applicantUser_DepID = this.userInfo.deptid
            this.flowFromData.Header_CreateDate = this.userInfo.datetime
            this.flowFromData = Object.assign(
              this.flowFromData,
              res.data.Process.FromData
            )
            this.flowFromData.Header_Document_Status =
              this.procinsstate[res.data.Process.flowstatus]
            this.checklisted = [
              {
                no: this.flowFromData.Header_applicantUserID,
                RealName: this.flowFromData.Header_applicantUserName,
                Name: this.flowFromData.Header_applicantUserName
              }
            ]
            this.flowhead = res.data.Process.flowhead
            this.DataPermission = {}

            this.loadDataPermission(res.data.Process.DataPermission)
            this.flowChart = res.data.Process.flowChart
            this.OperatePermission = res.data.Process.OperatePermission
            this.AttachmentPermission = res.data.Process.AttachmentPermission
            this.actid = res.data.Process.actid
            this.processName = res.data.Process.processName
            this.BusinessModuleID = res.data.Process.BusinessModuleID
            this.BusinessMoudle = res.data.Process.BusinessMoudle
            this.operateType = res.data.Process.operateType
            this.flowstatusName = res.data.Process.flowstatusName
            this.flowstatus = res.data.Process.flowstatus
            this.postData = res.data.Process.FlowTempContext
            this.postData.js = this.postData.js.replace('export default', '')
            this.propsData.DataPermission = this.DataPermission
            this.$refs.previewPagemain.previewinit({
              data: this.postData,
              propsData: this.propsData
            })
            this.LoadButton()
            if (
              !this.IsStrNull(this.ProcInsID) &&
              !this.IsStrNull(this.ActInsID) &&
              !this.IsStrNull(this.viewmodel)
            ) {
              /// 获取流程编号
              this.GetProcinstNumber({
                BusinessMoudle: this.BusinessMoudle,
                BusinessModuleID: this.BusinessModuleID
              })
            }
          } else {
            this.$message.error(res.msg)
          }
        })
      } else {
        this.$message.error('参数传入错误！')
      }
    },
    IsStrNull (str) {
      if (str === undefined) {
        return false
      }
      if (str === null) {
        return false
      }
      if (str.trim() === '') {
        return false
      }
      return true
    },
    /// 加载按钮权限
    LoadButton () {
      const actionButton = {}
      if (
        this.operateType === 'todo' ||
        this.operateType === 'draft' ||
        this.operateType === 'faqi'
      ) {
        this.OperatePermission.forEach(opt => {
          if (opt.IsVisible) {
            switch (opt.OperateType) {
              case 'Save':
                actionButton[opt.OperateType] = opt
                break
              case 'Start':
                actionButton[opt.OperateType] = opt
                break
              case 'Sendback':
                actionButton[opt.OperateType] = opt
                break
              case 'Approval':
                actionButton[opt.OperateType] = opt
                break
              case 'Abandon_App':
                actionButton[opt.OperateType] = opt
                break
              case 'Repeal_App':
                actionButton[opt.OperateType] = opt
                break
              case 'StartQuery':
                actionButton[opt.OperateType] = opt
                break
              case 'HastenWork':
                actionButton[opt.OperateType] = opt
                break
              case 'CopySend':
                actionButton[opt.OperateType] = opt
                break
              case 'Tranfer':
                actionButton[opt.OperateType] = opt
                break
              case 'Extend1':
                break
              case 'Extend2':
                break
              default:
                break
            }
          }
        })
      } else if (this.operateType === 'start') {
        this.OperatePermission.forEach(opt => {
          if (opt.IsVisible && opt.OperateType === 'Abandon') {
            actionButton[opt.OperateType] = opt
          }
          if (opt.IsVisible && opt.OperateType === 'Repeal') {
            actionButton[opt.OperateType] = opt
          }
        })
      } else if (this.operateType === 'quxiaogoutong') {
        actionButton.CancelQuery = {
          OperateName: '取消沟通',
          OperateType: 'CancelQuery',
          IsVisible: true,
          ShowName: '取消沟通'
        }
      } else if (this.operateType === 'goutong') {
        actionButton.AnswerQuery = {
          OperateName: '回复沟通',
          OperateType: 'AnswerQuery',
          IsVisible: true,
          ShowName: '回复沟通'
        }
      }
      actionButton.Print = {
        OperateName: '打印',
        OperateType: 'Print',
        IsVisible: true,
        ShowName: '打印'
      }
      this.OperatePermission = actionButton
      // $('.action').append(window.processButton.btnPrint)
    },
    GetProcinstNumber (param) {
      ApiGetProcinstNumber(param).then(res => {
        if (res.code === 0) {
          this.flowFromData.Header_formNumber = res.data
          this.$forceUpdate()
        }
      })
    },
    /// 跳转 btnFlowSkip
    funFlowSkip (comment) {
      this.AssemblData(
        {
          OperateName: '跳转',
          OperateType: 'FlowSkip',
          IsVisible: false,
          ShowName: '跳转'
        },
        comment
      )
    },
    /// 废弃 btnAbandon
    funAbandonOperation (comment) {
      this.AssemblData(this.OperatePermission.Abandon, comment)
    },
    /// 取消沟通 btnCancelQuery
    funCancerCommunication () { },
    /// 回复沟通 btnAnswerQuery
    funAnswerCommunication (comment) {
      console.log(comment)
    },
    /// 发起沟通 btnStartQuery
    funStartCommunication (comment) {
      console.log(comment)
    },
    /// 抄送 btnCopySend
    funCCOperation (comment) {
      console.log(comment)
    },
    /// 转办 btnTranfer
    funTurnOperation (comment) {
      this.AssemblData(this.OperatePermission.Tranfer, comment)
    },
    /// 拷贝为草稿 btnCopyStart
    funCopyStart () {
      this.$router.push({
        name: 'Flow/ProcessFrom',
        params: {
          processid: this.ProcID,
          CopyProcInsID: this.ProcInsID
        }
      })
    },
    /// 发起 btnStart
    funStartOperation () {
      this.$refs.elForm.validate(vid => {
        if (!vid) return
        this.fromcotrol.$refs.elForm.validate(valid => {
          if (!valid) return
          if (this.fromcotrol.submitValidate !== undefined) {
            if (this.fromcotrol.submitValidate() !== true) {
              return
            }
          }
          this.AssemblData(this.OperatePermission.Start)
        })
      })
    },
    AssemblData (action, operationInfo) {
      if (
        this.fromcotrol.beforeAssemblData !== undefined &&
        this.fromcotrol.beforeAssemblData() !== true
      ) {
        return
      }
      const param = {}
      param.operationInfo = operationInfo
      param.actionName = action.OperateName
      param.actionType = action.OperateType
      param.procID = this.ProcID
      param.procInsID = this.ProcInsID === '' ? 0 : this.ProcInsID
      param.actInsID = this.ActInsID === '' ? 0 : this.ActInsID
      param.fromdata = this.fromcotrol.formData
      param.cureentUserID = this.userInfo.userNo
      param.actID = this.actid
      param.prevActName = ''
      param.procname = this.processName
      HandleProcess(param).then(res => {
        if (res.code === 0) {
          this.$message.success(res.msg)
          if (action.type === 'btnSave') {
            if (
              param.fromdata.Header_Document_Status === '发起' ||
              param.fromdata.Header_Document_Status === '起草中'
            ) {
              this.$router.push({
                name: 'Flow/ProcessFrom',
                params: {
                  processid: param.ProcID,
                  processinsid: res.data,
                  actinsid: '',
                  viewmodel: 'draft'
                }
              })
            } else {
              setTimeout(() => {
                this.closewin()
              }, 1000)
            }
          } else if (
            action.type !== 'btnCopySend' &&
            action.type === 'btnCancelQuery'
          ) {
            this.$router.push({
              name: 'Flow/ProcessFrom',
              params: {
                processid: param.ProcID,
                processinsid: param.ProcInsID,
                actinsid: param.ActInsID,
                viewmodel: 'todo'
              }
            })
          } else if (action.type !== 'btnCopySend') {
            setTimeout(() => {
              this.closewin()
            }, 1000)
          }
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    closewin () {
      if (
        navigator.userAgent.indexOf('Firefox') !== -1 ||
        navigator.userAgent.indexOf('Chrome') !== -1
      ) {
        window.location.href = '/'
        window.close()
      } else {
        window.opener = null
        window.open('', '_self')
        window.close()
      }
    },
    /// 驳回 btnSendback
    funRejectOperation (comment) {
      this.AssemblData(this.OperatePermission.Sendback, comment)
    },
    /// 审批 btnApproval
    funApprovalOperation (comment) {
      debugger
      this.AssemblData(this.OperatePermission.Approval, comment)
    },
    /// 打印
    funOpenPrint () { },
    /// 申请人
    applicantUserConfirm (userlist) {
      this.flowFromData.Header_applicantUser_DepName = userlist[0].deptPName
      this.flowFromData.Header_applicantUser_DepID = userlist[0].deptPNo
      if (this.fromcotrol !== null) {
        this.fromcotrol.formData.Header_applicantUser_DepName = this.flowFromData.Header_applicantUser_DepName
        this.fromcotrol.formData.Header_applicantUser_DepID =
          userlist[0].deptPNo
        this.fromcotrol.formData.Header_applicantUserID = this.flowFromData.Header_applicantUserID
        this.fromcotrol.formData.Header_applicantUserName = this.flowFromData.Header_applicantUserName
      }
    },
    /// 窗体加载前方法
    initFrom (fromcotrol) {
      const fromdata = fromcotrol.data()
      fromdata.formData = Object.assign(fromdata.formData, this.flowFromData)
      for (const key in this.DataPermission) {
        fromdata.readDataPermission[key] = this.DataPermission[key].Read
        fromdata.writeDataPermission[key] = this.DataPermission[key].Write
        if (
          fromdata.modelfiled[key] !== undefined &&
          fromdata.modelfiled[key].length > 0
        ) {
          const filedname = fromdata.modelfiled[key]
          let requireditem
          for (let i = 0; i < fromdata.rules[filedname].length; i++) {
            const item = fromdata.rules[filedname][i]
            if (item.required !== undefined) {
              requireditem = item
              break
            }
          }
          /// 说明已经设置了必填
          if (requireditem !== undefined) {
            requireditem.required = this.DataPermission[key].Required
          } else {
            fromdata.rules[filedname].push({
              required: this.DataPermission[key].Required,
              message: '必填',
              trigger: 'blur'
            })
          }
        }
      }
      function data () {
        return fromdata
      }
      fromcotrol.data = data
    },
    /// 自定义表单加载完成方法
    loadfromcomplete (fromcotrol) {
      this.fromcotrol = fromcotrol
    },
    loadDataPermission (permissionlist) {
      for (const key in permissionlist) {
        this.DataPermission[key] = permissionlist[key]
        if (permissionlist[key].Children !== undefined) {
          this.loadDataPermission(permissionlist[key].Children)
        }
      }
    },
    processReject () {
      this.$refs.elForm.validate(vid => {
        if (!vid) return
        this.fromcotrol.$refs.elForm.validate(valid => {
          if (!valid) return
          if (this.fromcotrol.submitValidate !== undefined) {
            if (this.fromcotrol.submitValidate() !== true) {
              return
            }
          }
          this.$refs.RejectOperationDialog.visible = true
        })
      })
    },
    processApproval () {
      this.$refs.elForm.validate(vid => {
        if (!vid) return
        this.fromcotrol.$refs.elForm.validate(valid => {
          if (!valid) return
          if (this.fromcotrol.submitValidate !== undefined) {
            if (this.fromcotrol.submitValidate() !== true) {
              return
            }
          }
          this.$refs.ApprovalOperationDialog.visible = true
        })
      })
    },
    funSaveInfo () {
      this.AssemblData(this.OperatePermission.Save)
    }
  },
  watch: {
    'flowFromData.Header_formSubTitle' (val) {
      if (this.fromcotrol !== null) {
        this.fromcotrol.formData.Header_formSubTitle = val
      }
    },
    'flowFromData.Header_formNumber' (val) {
      if (this.fromcotrol !== null) {
        this.fromcotrol.formData.Header_formNumber = val
      }
    }
  }
}
</script>
<style>
.el-card__header {
  padding: 10px 10px;
}
.el-card__body {
  padding: 6px;
}
/* .el-form-item {
  margin-bottom: 5px;
} */
</style>
<style scoped>
.action {
  margin: 5px;
}
.el-button--default svg,
.el-button--default i {
  margin-right: 5px;
  padding-top: 1px;
}
.main {
  margin-left: 5px;
  margin-right: 5px;
}
</style>
